package com.mcintyret.site.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 * User: mcintyret2
 * Date: 15/04/2012
 */

@RequestMapping("/admin")
@Controller
public class AdminController extends BaseController {

    @Resource
    private AdminHelper adminHelper;

    @RequestMapping(method = RequestMethod.GET)
    public void adminPage(Model model) {
        model.addAttribute("users", adminHelper.getAllUsers());
        setupCommonElements(model);
    }

    @RequestMapping("/{username}")
    public String getUsername(
            @PathVariable String username,
            Model model) {
        model.addAttribute("journalFamilies", adminHelper.getAllJournalFamiliesForUser(username));
        model.addAttribute("user", adminHelper.getUser(username));
        return "user";
    }

}
